<template>
  <ul class="infinite-list" v-infinite-scroll="load" style="overflow:auto">
    <li v-for="(item, index) in list" class="infinite-list-item" :key="index">{{ item }}</li>
  </ul>
  <p v-if="loading">加载中...</p>
</template>
<script lang="ts">
import { pomelo } from "../../client";
import { defineComponent } from "vue";
import { ElMessage } from "element-plus";
import { getCookie, setCookie } from "@/utils/tools";
export default defineComponent({
  name: "chat-in",
  data: () => {
    return {
      loading: false,
      list: [1, 2, 3, 4, 5] as any[],
      params: {
      username: "",
      roomname: "",
      },
    };
  },
  computed: {},
  mounted() {
    console.log("Component mounted");
  },
  created() {
    
    console.log(this.$route.params.username);
    
    console.log(this.$route.params.roomid);
    // this.queryUserInfo();
  },
  methods: {
    queryUserInfo() {
      this.params.username = getCookie("username")||"";
    },
    quit() {
      this.$router.push({ name: "login-in" });
    },
    async sendChat() {
      var route = 'gate.gateHandler.queryEntry';
      pomelo.init({
        host: "127.0.0.1",
        port: 3014,
      }, () =>{
        pomelo.request(route, {
          uid: this.params.username
        }, function (data: { code: number; host: any; port: any; }) {
          pomelo.disconnect();
          if (data.code === 500) {
            // showError(LOGIN_ERROR);
            return;
          }
          // callback(data.host, data.port);
        });
      });
    },
    load () {
        this.loading = true;
        // this.list.push({id:6, name: "test6", age: 6});
    },
    //校验
    validate() {
      if (this.params.username.length < 2) {
        ElMessage({
          message: "用户名不能少于2位",
          type: "warning",
        });
        return false;
      }
    },
  },
});
</script>